<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ChangeMoviesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('movies', function (Blueprint $table) {
            if (Schema::hasColumn('movies', 'type')) {
                $table->dropColumn('type'); // 删除分类
            }
            if (Schema::hasColumn('movies', 'updated_desc')) {
                $table->dropColumn('updated_desc'); //
            }
            if (Schema::hasColumn('movies', 'last_updated')) {
                $table->dropColumn('last_updated');
            }
            if (Schema::hasColumn('movies', 'section_updated')) {
                $table->dropColumn('section_updated');
            }
            if (Schema::hasColumn('movies', 'section')) {
                $table->dropColumn('section');
            }
            if (Schema::hasColumn('movies', 'top_image')) {
                $table->dropColumn('top_image');
            }
            
            if( ! Schema::hasColumn('movies', 'cover')) {
                $table->string('cover')->comment('封面')->nullable();
            }
            if (!Schema::hasColumn('movies', 'outher_name')) {
                $table->string('outher_name')->nullable()->comment('别名 / 其他名称');
            }
            if (!Schema::hasColumn('movies', 'published_at')) {
                $table->json( 'published_at')->comment('上映时间')->nullable();
            }
            if (!Schema::hasColumn('movies', 'score_people')) {
                $table->integer('score_people')->unsigned()->default(0)->comment('评分人数');
            }
            if (!Schema::hasColumn('movies', 'runtime')) {
                $table->integer('runtime')->unsigned()->default(0)->comment('时长');
            }
            if (!Schema::hasColumn('movies', 'language')) {
                $table->json('language')->nullable()->comment('语言');
            }
            if (!Schema::hasColumn('movies', 'imdb')) {
                $table->string('imdb')->nullable()->comment('IMDb 链接');
            }
            if (!Schema::hasColumn('movies', 'year')) {
                $table->integer('year')->default(0)->unsigned()->comment('年份');
            }
            if (!Schema::hasColumn('movies', 'douban_id')) {
                $table->integer('douban_id')->default(0)->unsigned()->comment('豆瓣唯一 ID');
            }
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('movies', function (Blueprint $table) {
            if (! Schema::hasColumn('movies', 'type')) {
                $table->string('type')->comment('类型')->nullable();
            }
            if (!Schema::hasColumn('movies', 'updated_desc')) {
                $table->string('updated_desc')->comment('更新')->nullable();
            }
            if (!Schema::hasColumn('movies', 'last_updated')) {
                $table->timestamp('last_updated')->comment('最后更新时间')->nullable();
            }
            if (!Schema::hasColumn('movies', 'section')) {
                $table->integer('section')->default(0)->comment('集数');
            }
            if (!Schema::hasColumn('movies', 'section_updated')) {
                $table->integer('section_updated')->default(0)->comment('更新集数');
            }
            if (Schema::hasColumn('movies', 'language')) {
                $table->dropColumn('language');
            }
            if (Schema::hasColumn('movies', 'cover')) {
                $table->dropColumn('cover');
            }
            if (Schema::hasColumn('movies', 'outher_name')) {
                $table->dropColumn('outher_name');
            }
            if (Schema::hasColumn('movies', 'published_at')) {
                $table->dropColumn( 'published_at');
            }
            if (Schema::hasColumn('movies', 'year')) {
                $table->dropColumn('year');
            }
            if (Schema::hasColumn('movies', 'runtime')) {
                $table->dropColumn('runtime');
            }
            if (Schema::hasColumn('movies', 'score_people')) {
                $table->dropColumn('score_people');
            }
            if (Schema::hasColumn('movies', 'imdb')) {
                $table->dropColumn('imdb');
            }
            if (Schema::hasColumn('movies', 'douban_id')) {
                $table->dropColumn('douban_id');
            }
        });
    }
}
